{include file="common/head"}

<head>
    <title>订单出货统计</title>

    <style>
        a {
            text-decoration: none;
        }

        input {
            display: initial !important;
        }
    </style>
    <link rel="stylesheet" href="/static/flatpickr/flatpickr.min.css">
    <script src="/static/flatpickr/flatpickr.min.js"></script>
</head>

<body>
    <div class="container-fluid">
        <div class="row">
            <div class="col-3 fs-2">
                客户订单出货统计
            </div>
            <div class="col">
                <form action="/order/delivery_analyze" method="post">
                    <div class="row" id="query_bar" style="height: 50px;line-height: 50px;">
                        <div class="col">
                            <label for="customer">客户：</label>
                            <select name="customer" class="form-control" style="width:140px;display:initial;">
                                <option value="">所有</option>
                                {foreach $customer_list as $k=>$v}
                                <option value="{$v['id']}" {if $v['id']==$customer} selected{/if}>{$v['name']}</option>
                                {/foreach}
                            </select>

                            <label for="sdate">日期：</label>
                            <input class="form-control" type="text" value="{$sdate}" id="sdate" name="sdate"
                                placeholder="开始日期" />

                            <label for="edate">
                                <input class="form-control" type="text" value="{$edate}" id="edate" name="edate"
                                    placeholder="结束日期" />
                            </label>

                            <label for="po">客户PO#</label>
                            <input class="form-control" type="text" value="{$po}" id="po" name="po"
                                placeholder="客户订单号" />
                            </label>

                            <button type="button" class="btn btn-warning query">
                                <span class="bi-search"></span>
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <table class="table table-bordered" style="width: inherit!important;;overflow: scroll;">

            <tbody>
                {foreach $list as $k=>$kv}
                <!--startprint_{$kv['id']}-->
                <tr>
                    <td>
                        <div class="row">
                            <div class="col">
                                <span style="color:red;font-size:large">TO:{$kv['customer_name']}</span>
                            </div>
                            <div class="col">
                                <span style="color:red;font-size:large">FROM:{$sys['company_name']}</span>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col">
                                <span style="color:red;">Address:{$kv['customer_address']}</span>
                            </div>
                            <div class="col">
                                <span style="color:red;">Address:{$sys['address']}</span>
                            </div>
                        </div>
                        <div class="text-primary fs-4">
                            采购单号：{$kv['order_no']}
                        </div>
                        <table class="table table-sm table-hover table-striped table-bordered">
                            {if $kv['list_sum']>0}
                            <thead class="table-info">
                                <th>送货单号 </th>
                                <th>出货时间 </th>
                                <th>图纸编号 Item</th>
                                <th>品名规格 Specs</th>
                                <th>数量 Qty</th>
                                <th>单位 Unit</th>
                                <th>单价 Price(USD)</th>
                                <th>金额 Amount</th>
                                <th>备注</th>
                            </thead>

                            {foreach $kv['list'] as $item}
                            <tr>
                                <td>{$item['delivery_id']}</td>
                                <td>{$item['create_time']}</td>
                                <td>{$item['goods_id_name']}</td>
                                <td>{$item['specs_id_name']}</td>
                                <td>{$item['qty']}</td>
                                <td>{$item['unit']}</td>
                                <td>{$currency_symbol}{$item['price']}</td>
                                <td>{$currency_symbol}{$item['amount']}</td>
                                <td>{$item['memo']}</td>
                            </tr>
                            {/foreach}
                            <tr>
                                <td colspan="7">Total</td>
                                <td>{$currency_symbol}{$kv['list_sum']}</td>
                                <td></td>
                            </tr>
                            {else}
                            订单在本时间段内无出货
                            {/if}
                        </table>
                    </td>
                </tr>
                <!--endprint_{$kv['id']}-->
                <tr>
                    <td style="border:0;">
                        <button class="btn btn-sm btn-primary" type="button" onclick="printpage({$kv.id});">
                            <span class="bi-printer">Print {$kv['order_no']}</span> 
                        </button>
                        <button class="btn btn-sm btn-info" type="button" onclick="excel({$kv.id});">
                            <span class="bi-file-excel">Export Excel {$kv['order_no']}</span>
                        </button>

                    </td>
                </tr>

                {/foreach}

            </tbody>
        </table>

    </div>

    </div>

</body>

<script type="text/javascript">

    $(document).ready(function () {

        var check_ids = [];

        flatpickr("#sdate", {});
        flatpickr("#edate", {});

        $(".sdate").flatpickr({
            enableTime: true,
            dateFormat: "Y-m-d H:i:s",
        });
        $(".edate").flatpickr({
            enableTime: true,
            dateFormat: "Y-m-d H:i",
        });

        $('.query').on('click', function () {
            $('form').submit();
        })

        $(".btn_cancel").on('click', function () {
            var oid = $(this).attr('id');
            layer.confirm('是否确认删除出货单？', {
                btn: ['Yes', 'No'] //按钮
            }, function () {

                $.post("/index.php/order/order_cancel", { table: 'delivery', id: oid, name: '出货单', slave_table: 'delivery_list|delivery_id' }, function (res) {
                    console.log(res.msg)
                    if (res.code) {
                        location.reload();
                    } else {
                        layer.open({ 'content': res.msg });
                    }

                });

            }, function () {
                layer.msg('取消操作!');
            });

        })

    })

    function printpage(index) {
        if (!index) return;
        let oldStr = window.document.body.innerHTML; // 获取body的内容
        let start = "<!--startprint_" +index+"-->"; // 开始打印标识, 17个字符
        let end = "<!--endprint_" + index + "-->"; // 结束打印标识
        let newStr = oldStr.substr(oldStr.indexOf(start) + 20); // 截取开始打印标识之后的内容
        newStr = newStr.substring(0, newStr.indexOf(end)); // 截取开始打印标识和结束打印标识之间的内容
        window.document.body.innerHTML = newStr; // 把需要打印的指定内容赋给body
        window.print(); // 调用浏览器的打印功能打印指定区域
        window.document.body.innerHTML = oldStr; // body替换为原来的内容
    }

    function excel(order_id){
        location.href="/order/order_delivery_csv/order_id/"+order_id;
    }


</script>

</body>

</html>